package cn.stylefeng.guns.modular.storage.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.storage.entity.StorageAllocationOut;
import cn.stylefeng.guns.modular.storage.mapper.StorageAllocationOutMapper;
import cn.stylefeng.guns.modular.storage.model.params.StorageAllocationOutParam;
import cn.stylefeng.guns.modular.storage.model.result.StorageAllocationOutResult;
import  cn.stylefeng.guns.modular.storage.service.StorageAllocationOutService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 调拨出库表 服务实现类
 * </p>
 *
 * @author zhucx
 * @since 2021-12-02
 */
@Service
public class StorageAllocationOutServiceImpl extends ServiceImpl<StorageAllocationOutMapper, StorageAllocationOut> implements StorageAllocationOutService {

    @Override
    public void add(StorageAllocationOutParam param){
        StorageAllocationOut entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(StorageAllocationOutParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(StorageAllocationOutParam param){
        StorageAllocationOut oldEntity = getOldEntity(param);
        StorageAllocationOut newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public StorageAllocationOutResult findBySpec(StorageAllocationOutParam param){
        return null;
    }

    @Override
    public List<StorageAllocationOutResult> findListBySpec(StorageAllocationOutParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(StorageAllocationOutParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition,operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(StorageAllocationOutParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private StorageAllocationOut getOldEntity(StorageAllocationOutParam param) {
        return this.getById(getKey(param));
    }

    private StorageAllocationOut getEntity(StorageAllocationOutParam param) {
        StorageAllocationOut entity = new StorageAllocationOut();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
